import { sendMessageByWs } from "@/config/websocket.js"

const http = uni.$u.http;

let baseUrl = http.config.baseURL;
if (baseUrl && baseUrl.endsWith("/")) {
    baseUrl = baseUrl.substring(0, baseUrl.length - 1);
}

// 使用方式： uni.$u.http.api.login(params).then(data => {}).catch(err => {})
const sysCfg = (params, config = {}) => http.get(baseUrl + "/config", params, config);
const token = (params, config = {}) => http.get(baseUrl + "/token", params, config);

const login = (params, config = {}) => http.post(baseUrl + "/login", params, config);
const register = (params, config = {}) => http.post(baseUrl + "/reg", params, config);
const pay = (params, config = {}) => http.post(baseUrl + "/pay", params, config);
const checkChat = (params, config = {}) => http.post(baseUrl + "/checkChat", params, config);

export default {
	sendMessageByWs,
	sysCfg,
	login,
	register,
	pay,
	token,
	checkChat
}